package com.cqut.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cqut.service.IProcessDetailService;
import com.cqut.model.ProcessDetail;
import com.cqut.dao.ProcessDetailMapper;
import com.cqut.dao.ProcessDetailMapperExtra;
import com.cqut.dto.LimitShowDTO;
import com.cqut.util.SqlUtil;

@Service
public class ProcessDetailService implements IProcessDetailService {
    @Resource(name="processDetailMapper")
    private ProcessDetailMapper processDetailMapper;
    @Resource(name="processDetailMapperExtra")
    private ProcessDetailMapperExtra processDetailMapperExtra;

    @Override
    public boolean save(ProcessDetail processDetail) {
        return processDetailMapper.insert(processDetail) > 0;
    }

    @Override
    public boolean update(ProcessDetail processDetail) {
        return processDetailMapper.updateByPrimaryKeySelective(processDetail) >= 0;
    }

    @Override
    public boolean delete(String processDetailId) {
        return processDetailMapper.deleteByPrimaryKey(processDetailId) > 0;
    }

    @Override
    public boolean batchDelete(String[] primaryKeys) {
        return processDetailMapper.deleteByPrimaryKeys(primaryKeys) > 0;
    }

    @Override
    public ProcessDetail findModel(String processDetailId) {
        return processDetailMapper.selectByPrimaryKey(processDetailId);
    }

    @Override
    public ProcessDetail findModel(String processDetailId, String[] parameters) {
        return processDetailMapper.findModel(processDetailId, SqlUtil.formatParameters(parameters));
    }

    public Map<String, Object> findMap(String processDetailId) {
        String[][] parameters = {{"process_name", "processName"}, {"process_detail_id", "processDetailId"}, {"process_id", "processId"}, {"game_time", "gameTime"}, {"review_version_id", "reviewVersionId"}, {"review_start_time", "reviewStartTime"}, {"review_end_time", "reviewEndTime"}, {"works", "works"}, {"works_start_time", "worksStartTime"}, {"works_end_time", "worksEndTime"}, {"file_id", "fileId"}, {"parent_game_id", "parentGameId"}};
        return this.findMap(processDetailId, parameters);
    }

    public Map<String, Object> findMap(String processDetailId, String[][] parameters) {
        return processDetailMapper.findMap(processDetailId, SqlUtil.formatParametersForAlias(parameters));
    }

    @Override
    public List<ProcessDetail> loadModels() {
        return this.loadModels(null, null, null, null, -1, -1);
    }

    @Override
    public List<ProcessDetail> loadModels(String condition, Object[] values, String order, String sort, int curPage, int limit) {
        return this.loadModels(null, condition, values, order, sort, curPage, limit);
    }

    @Override
    public List<ProcessDetail> loadModels(String[] parameters, String condition, Object[] values, String order, String sort, int curPage, int limit) {
        return processDetailMapper.loadModels(SqlUtil.formatParameters(parameters), SqlUtil.fillCondition(condition, values), order, sort, SqlUtil.getOffset(curPage, limit), limit);
    }

    @Override
    public List<Map<String, Object>> loadMaps() {
        String[][] parameters = {{"process_detail_id", "processDetailId"}, {"process_id", "processId"}, {"game_time", "gameTime"}, {"review_version_id", "reviewVersionId"}, {"review_start_time", "reviewStartTime"}, {"review_end_time", "reviewEndTime"}, {"works", "works"}, {"works_start_time", "worksStartTime"}, {"works_end_time", "worksEndTime"}, {"file_id", "fileId"}, {"parent_game_id", "parentGameId"}};
        return this.loadMaps(parameters, null, null, null, null, -1, -1);
    }

    @Override
    public List<Map<String, Object>> loadMaps(String condition, Object[] values, String order, String sort, int curPage, int limit) {
        String[][] parameters = {{"process_detail_id", "processDetailId"}, {"process_id", "processId"}, {"game_time", "gameTime"}, {"review_version_id", "reviewVersionId"}, {"review_start_time", "reviewStartTime"}, {"review_end_time", "reviewEndTime"}, {"works", "works"}, {"works_start_time", "worksStartTime"}, {"works_end_time", "worksEndTime"}, {"file_id", "fileId"}, {"parent_game_id", "parentGameId"}};
        return this.loadMaps(parameters, condition, values, order, sort, curPage, limit);
    }

    @Override
    public List<Map<String, Object>> loadMaps(String[][] parameters, String condition, Object[] values, String order, String sort, int curPage, int limit) {
        return processDetailMapper.loadMaps(SqlUtil.formatParametersForAlias(parameters), SqlUtil.fillCondition(condition, values), order, sort, SqlUtil.getOffset(curPage, limit), limit);
    }

    @Override
    public long count() {
        return this.count(null, false);
    }

    @Override
    public long count(String condition, Object[] values) {
        return this.count(null, condition, values, false);
    }

    @Override
    public long count(String[] parameters, boolean isDistinct) {
        return this.count(parameters, null, null, isDistinct);
    }

    @Override
    public long count(String[] parameters, String condition, Object[] values, boolean isDistinct) {
        return processDetailMapper.count(SqlUtil.formatParameters(parameters), SqlUtil.fillCondition(condition, values), isDistinct);
    }

	@Override
	public List<Map<String, Object>> getUsageList(String reviewVersionId,
			String competitionName, LimitShowDTO limitShowDTO) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Map<String, Object>> findProcessDetail(String comProcessId, String processName, LimitShowDTO limitShowDTO) {
		return processDetailMapperExtra.findProcessDetail(comProcessId, processName, limitShowDTO.calculateStart(), limitShowDTO.calculateEnd());
	}

	@Override
	public long countProcessDetail(String comProcessId, String processName) {
		return processDetailMapperExtra.countProcessDetail(comProcessId, processName);
	}

 
    
}
